import 'package:safetymonitor/app/core/core.dart';

/// @Author: leijingxing
/// @Date: 2023-03-17
/// @LastEditTime: 2023-03-17 13:58
/// @LastEditors: leijingxing
/// @Description: 封装toast,方便后期统一修改toast样式
/// demo:
/// ```dart
/// AppToast.show('提示');
/// AppToast.showSuccess('成功');
/// AppToast.showError('失败');
/// AppToast.showWarning('警告');
/// ```
class AppToast {
  const AppToast({
    required this.text,
    required this.cancelFunc,
    Key? key,
    this.title,
    this.icon,
    this.iconColor,
    this.actionText,
    this.onActionClick,
  });

  final IconData? icon;
  final Color? iconColor;
  final String text;
  final String? title;
  final String? actionText;
  final VoidCallback? onActionClick;
  final void Function() cancelFunc;

  static show(
    String text, {
    String? title,
    Duration? duration = const Duration(seconds: 1),
    IconData? icon = Icons.info,
    Color? iconColor = Colors.white,
    String? actionText,
    VoidCallback? onActionClick,
    VoidCallback? onClose,
    bool crossPage = true,
  }) {
    if (text.isEmpty) return;
    Get.snackbar(
      title ?? '提示',
      text,
      icon: icon != null ? Icon(icon, color: iconColor) : null,
      duration: duration,
      animationDuration: const Duration(milliseconds: 300),
      margin: const EdgeInsets.all(25),
      padding: const EdgeInsets.all(10),
      isDismissible: true,
      snackPosition: SnackPosition.TOP,
      backgroundColor: Colors.black87,
      colorText: Colors.white,
      forwardAnimationCurve: Curves.easeOutCubic,
      reverseAnimationCurve: Curves.easeInCubic,
      borderRadius: 8,
      overlayColor: Colors.transparent,
    );
  }

  /// 显示成功提示
  static showSuccess(
    String text, {
    String? title,
    Duration? duration = const Duration(seconds: 1),
    String? actionText,
    VoidCallback? onActionClick,
    VoidCallback? onClose,
    bool crossPage = true,
    Alignment alignment = const Alignment(0, 0.8),
  }) {
    return show(
      text,
      title: title,
      duration: duration,
      icon: Icons.task_alt_outlined,
      iconColor: AppColors.meaning_color_success,
      actionText: actionText,
      onActionClick: onActionClick,
      onClose: onClose,
      crossPage: crossPage,
    );
  }

  /// 显示错误提示
  static showError(
    String text, {
    String? title,
    Duration? duration = const Duration(seconds: 1),
    String? actionText,
    VoidCallback? onActionClick,
    VoidCallback? onClose,
    bool crossPage = true,
    Alignment alignment = const Alignment(0, 0.8),
  }) {
    return show(
      text,
      title: title,
      duration: duration,
      icon: Icons.error_outline_outlined,
      iconColor: AppColors.meaning_color_danger,
      actionText: actionText,
      onActionClick: onActionClick,
      onClose: onClose,
      crossPage: crossPage,
    );
  }

  /// 显示警告提示
  static showWarning(
    String text, {
    String? title,
    Duration? duration = const Duration(seconds: 1),
    String? actionText,
    VoidCallback? onActionClick,
    VoidCallback? onClose,
    bool crossPage = true,
    Alignment alignment = const Alignment(0, 0.8),
  }) {
    return show(
      text,
      title: title,
      duration: duration,
      icon: Icons.warning_amber_rounded,
      iconColor: const Color(0xFFFA8442),
      actionText: actionText,
      onActionClick: onActionClick,
      onClose: onClose,
      crossPage: crossPage,
    );
  }
}
